﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;

namespace TP2
{
    public partial class EditRateForm : Form
    {
        RateForm rateFrom;
        string operation;
        string client;
        int id_rate;
        string title;
        int period;
        int procent;
        int tab_index;
        public EditRateForm(int tab_index,string operationType, string clientType, int idRate, string titleRate, int procentRate, int periodRate,RateForm RF)
        {
            this.rateFrom = RF;
            operation = operationType;
            client = clientType;
            title = titleRate;
            procent = procentRate;
            period = periodRate;
            id_rate = idRate;
            this.tab_index = tab_index;
            InitializeComponent();
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string title = textBoxTitle.Text;
                Double procent = Convert.ToInt32(textBoxProcent.Text);
                int period = Convert.ToInt32(textBoxPeriod.Text);
                DBWorkClass dbWork = new DBWorkClass();
                dbWork.UpdateRate(title, procent, period, client, id_rate, tab_index);
                rateFrom.Refresh();
                this.Close();
            }
            catch (FormatException) { MessageBox.Show("ошибка во входных данных"); }
        }

        private void EditRateForm_Load(object sender, EventArgs e)
        {
            textBoxTitle.Text = title;
            textBoxProcent.Text = procent.ToString();
            textBoxPeriod.Text = period.ToString();
            labelClientType.Text = client;
            labelOperationType.Text = operation;
        }
    }
}
